package user

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"weekly-exam/config"
	"weekly-exam/internal/model/dao"
)

type Updates struct {
	FriendId int `form:"friendId" json:"friendId" xml:"friendId" binding:"required"`
}

func Update(c *gin.Context) {
	var json Updates
	if err := c.ShouldBindJSON(&json); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	friendId := json.FriendId
	var message dao.Message
	config.DB.Where("friend_id=?", friendId).First(&message)
	if message.Content == "" {
		c.JSON(http.StatusBadRequest, gin.H{"error": "没有消息"})
		return
	}
	config.DB.Model(&message).Update("status", 1)
	c.JSON(http.StatusOK, gin.H{
		"message": "修改成功",
	})
	return
}
